namespace DotNetNuke.Services.Localization
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Reflection;

    /// <summary>
    /// Represents a collection of <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> objects.
    /// </summary>
    public class LocaleFileCollection : CollectionBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> class.
        /// </summary>
        public LocaleFileCollection()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> class containing the elements of the specified source collection.
        /// </summary>
        /// <param name="value">A <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> with which to initialize the collection.</param>
        public LocaleFileCollection(LocaleFileCollection value)
        {
            this.AddRange(value);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> class containing the specified array of <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> objects.
        /// </summary>
        /// <param name="value">An array of <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> objects with which to initialize the collection. </param>
        public LocaleFileCollection(LocaleFileInfo[] value)
        {
            this.AddRange(value);
        }

        /// <summary>
        /// Add an element of the specified <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> to the end of the collection.
        /// </summary>
        /// <param name="value">An object of type <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> to add to the collection.</param>
        public int Add(LocaleFileInfo value)
        {
            return this.List.Add(value);
        }

        /// <summary>
        /// Adds the contents of another <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> to the end of the collection.
        /// </summary>
        /// <param name="value">A <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> containing the objects to add to the collection. </param>
        public void AddRange(LocaleFileCollection value)
        {
            int refIntHelperL0 = value.Count - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                this.Add((LocaleFileInfo) value.List[i]);
            }
        }

        /// <summary>
        /// Copies the elements of the specified <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> array to the end of the collection.
        /// </summary>
        /// <param name="value">An array of type <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> containing the objects to add to the collection.</param>
        public void AddRange(LocaleFileInfo[] value)
        {
            int refIntHelperL0 = value.Length - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                this.Add(value[i]);
            }
        }

        /// <summary>
        /// Gets a value indicating whether the collection contains the specified <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see>.
        /// </summary>
        /// <param name="value">The <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> to search for in the collection.</param>
        /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
        public bool Contains(LocaleFileInfo value)
        {
            return this.List.Contains(value);
        }

        /// <summary>
        /// Copies the collection objects to a one-dimensional <see cref="T:System.Array">Array</see> instance beginning at the specified index.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="T:System.Array">Array</see> that is the destination of the values copied from the collection.</param>
        /// <param name="index">The index of the array at which to begin inserting.</param>
        public void CopyTo(LocaleFileInfo[] array, int index)
        {
            this.List.CopyTo(array, index);
        }

        private LocaleFileInfo GetLocaleFile(string FullFileName)
        {
            IEnumerator refObjectHelperL0=null;
            try
            {
                refObjectHelperL0 = this.List.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    LocaleFileInfo LocaleFile = (LocaleFileInfo) refObjectHelperL0.Current;
                    if (LocaleFileUtil.GetFullFileName(LocaleFile).Replace(@"\", "/") == FullFileName.Replace(@"\", "/"))
                    {
                        return LocaleFile;
                    }
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            return null;
        }

        /// <summary>
        /// Gets the index in the collection of the specified <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see>, if it exists in the collection.
        /// </summary>
        /// <param name="value">The <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> to locate in the collection.</param>
        /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns>
        public int IndexOf(LocaleFileInfo value)
        {
            return this.List.IndexOf(value);
        }

        /// <summary>
        /// Add an element of the specified <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> to the collection at the designated index.
        /// </summary>
        /// <param name="index">An <see cref="T:System.Int32">Integer</see> to indicate the location to add the object to the collection.</param>
        /// <param name="value">An object of type <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> to add to the collection.</param>
        public void Insert(int index, LocaleFileInfo value)
        {
            this.List.Insert(index, value);
        }

        /// <summary>
        /// Remove the specified object of type <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> from the collection.
        /// </summary>
        /// <param name="value">An object of type <see cref="T:DotNetNuke.Services.Localization.LocaleFileInfo">LocaleFileInfo</see> to remove to the collection.</param>
        public void Remove(LocaleFileInfo value)
        {
            this.List.Remove(value);
        }

        /// <summary>
        /// Creates a one-dimensional <see cref="T:System.Array">Array</see> instance containing the collection items.
        /// </summary>
        /// <returns>Array of type LocaleFileInfo</returns>
        public LocaleFileInfo[] ToArray()
        {
            LocaleFileInfo[] arr=null;
            arr = (LocaleFileInfo[]) Utils.CopyArray((Array) arr, new LocaleFileInfo[(this.Count - 1) + 1]);
            this.CopyTo(arr, 0);
            return arr;
        }

        /// <summary>
        /// Gets the <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> at the specified index in the collection.
        /// <para>
        /// In VB.Net, this property is the indexer for the <see cref="T:DotNetNuke.Services.Localization.LocaleFileCollection">LocaleFileCollection</see> class.
        /// </para>
        /// </summary>
        public LocaleFileInfo this[int index]
        {
            get
            {
                return (LocaleFileInfo) this.List[index];
            }
            set
            {
                this.List[index] = value;
            }
        }

        public LocaleFileInfo this[string FullFileName]
        {
            get
            {
                return this.GetLocaleFile(FullFileName);
            }
            set
            {
                if (this.GetLocaleFile(FullFileName) == null)
                {
                    throw new ArgumentOutOfRangeException(FullFileName, FullFileName + " does not exist in this collection.");
                }
                LocaleFileInfo LocaleFile = value;
            }
        }

        internal LocaleFileInfo get_LocaleFile(string fullFileName)
        {
            return GetLocaleFile(fullFileName);
        }

        internal void set_LocaleFile(string fullFileName,LocaleFileInfo newValue)
        {
            LocaleFileInfo localFile = GetLocaleFile(fullFileName);
            if (localFile != null)
                localFile = newValue;
            else
                throw new ArgumentOutOfRangeException(fullFileName, fullFileName + " does not exist in this collection.");
        }


    }
}

